{extend name="base/form" /}
{block name="title"} 首页 {/block}
<!-- Page Content -->
{block name="content"}
<form class="layui-form" style="padding-right: 38px;padding-top: 10px">

    <input type="hidden" name="id" value="{$data.id}">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text"  value="{$data.name}"  autocomplete="off"  class="layui-input  layui-disabled">
            <div class="layui-form-mid layui-word-aux">用户名不支持修改</div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">
            用户角色
        </label>
        <div class="layui-input-block">
            <select lay-filter="aihao" name="group_id">
                </option>
                {volist name='role' id='vo'}
                <option {eq name="data.group_id" value="$vo.id" } selected {/eq}  value="{$vo.id}">{$vo.title}</option>
                {/volist}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">密&nbsp;&nbsp;&nbsp;码</label>
        <div class="layui-input-block">
            <input type="password" id="password"  name="password"   placeholder="请输入密码" autocomplete="off" class="layui-input">
            <div class="layui-form-mid layui-word-aux">密码不改留空</div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">确&nbsp;&nbsp;&nbsp;认</label>
        <div class="layui-input-block">
            <input type="password"  id="check_password"  name="check_password"  placeholder="请确认密码" autocomplete="off" class="layui-input">
            <div class="layui-form-mid layui-word-aux">密码不改留空</div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">状&nbsp;&nbsp;&nbsp;态</label>
        <div class="layui-input-block">
            <input type="checkbox" name="state"  {eq name="data.state" value="0"}  checked  {/eq} lay-skin="switch" lay-text="开启|禁用" value="0" >
        </div>

    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button style="margin-left: 20%" class="layui-btn" lay-submit="*" lay-filter="addSubmit">提交</button>
            <button id="reset" type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<!-- /Page Content -->
{/block}
{block name="js"}
<script>
    layui.use(['form','layer'], function(){
        var form  = layui.form;
        var layer = layui.layer;
        var $     = layui.jquery;
        //当你在iframe页面关闭自身时
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        //监听提交
        form.on('submit(addSubmit)', function(data){
            console.log(data.field)
            $.ajax({
                url:"{:url('editPost')}",
                type:'post',
                data:data.field,
                success:function(e){
                    if(e.code == 1){
                        layer.msg(e.msg,{icon:6,time:2000},function (){
                            parent.layer.close(index); //再执行关闭
                            window.location.reload()
                        })
                    }else{
                        layer.msg(e.msg,{icon:5,time:2000},function (){
                            // parent.layer.close(index); //再执行关闭
                            // window.location.reload()
                        })
                    }
                }
            });
            return false;
        });
    });
</script>
{/block}